package com.mark.mall.web.platform.controller;


import com.mark.mall.web.platform.dto.CartListDTO;
import com.mark.mall.web.platform.dto.param.CartAddParam;
import com.mark.mall.common.resultBean.R;
import com.mark.mall.web.platform.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-03-03
 */
@RestController
@RequestMapping("/web/cart")
@Api(tags = "购物车模块")
@RequiredArgsConstructor
public class CartController {
    private final CartService cartService;

    @ApiOperation(value = "前台新增购物车列表", httpMethod = "GET")
    @GetMapping("list")
    public R<List<CartListDTO>> list(String memberId) {
        return cartService.cartList(memberId);
    }

    @ApiOperation(value = "前台新增购物车功能", httpMethod = "POST")
    @PostMapping("add")
    public R<Boolean> addCart(@RequestBody @Valid List<CartAddParam> list) {
        return cartService.addCart(list);
    }

    @ApiOperation(value = "前台删除购物车功能", httpMethod = "POST")
    @PostMapping("del")
    public R<Boolean> delCart(String id) {
        return cartService.delCart(id);
    }

    @ApiOperation(value = "前台购物车修改数量功能", httpMethod = "POST")
    @PostMapping("updateNum")
    public R<Boolean> updateCartNum(String id, int num) {
        return cartService.updateCartNum(id, num);
    }
}
